﻿using System;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Text;
using System.Web;

namespace AFI.Speargun.Web.Helpers
{
    public static class NavigationMenuHelper
    {
        public static string SiteMapPath(this HtmlHelper helper)
        {
            return String.Empty;
        }

        public static string NavigationMenuItem(this HtmlHelper helper, bool first, string linkText, string actionName, string controllerName)
        {
            TagBuilder li = new TagBuilder("li");
            if (first)
                li.AddCssClass("first");
            if (IsCurrentAction(helper, actionName, controllerName))
                li.AddCssClass("active");

            li.InnerHtml = LinkExtensions.ActionLink(helper, linkText, actionName, controllerName);

            return li.ToString(TagRenderMode.Normal);
        }

        private static bool IsCurrentAction(HtmlHelper helper, string actionName, string controllerName)
        {
            string currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
            string currentActionName = (string)helper.ViewContext.RouteData.Values["action"];

            if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) && currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
                return true;

            return false;
        }
    }
}
